/**
 * Copyright by e-shion.net
 */
package net.xfok.ui.custom;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

/**
 * @author 2011-1-4 Howard
 * 
 */
public class MyView extends View {
	private static int SIZE=100;
	private int X=0;
	private int mX;
	private int mY;

	public MyView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public MyView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

	 public MyView(Context context, AttributeSet attrs, int defStyle) {
	        super(context, attrs, defStyle);
	 }

	@Override
	public void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		for(int i=X;i<mX;i++){
			if(i%10==0){
				Paint paint = new Paint();
				paint.setColor(Color.WHITE);
				paint.setStyle(Style.FILL);		
				canvas.drawRect(new Rect(i, mY, i + SIZE, mY + SIZE), paint);
			}else{
				Paint paint = new Paint();
				paint.setColor(Color.GREEN);
				paint.setStyle(Style.FILL);		
				canvas.drawRect(new Rect(i, mY, i + SIZE, mY + SIZE), paint);
			}
		}
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		Log.i("MyView", "X="+event.getX());
		super.onTouchEvent(event);
		mX = (int) event.getX();
		mY=(int)event.getY();
		invalidate();
		return true;
	}
}
